package org.androidpn;

import java.io.File;

import org.androidpn.client.AppException;
import org.androidpn.http.HttpManager;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.nostra13.universalimageloader.utils.StorageUtils;

import android.app.Application;
import android.graphics.Bitmap;

public class HospitalClientApplication extends Application {
	private static HospitalClientApplication mInstance;

	public static synchronized HospitalClientApplication getmInstance() {
		return mInstance;
	}

	private static DisplayImageOptions defaultoptions;

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		mInstance = this;
		// 异常捕捉
		AppException.getInstance().init(this);
		HttpManager.init(this);
		defaultoptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.default_icon)
				// resource or drawable
				.showImageForEmptyUri(R.drawable.default_icon)
				// resource or drawable
				.showImageOnFail(R.drawable.default_icon)
				// .showImageOnFail(R.color.color_e7e7e7)
				// resource or drawable
				.resetViewBeforeLoading(false).cacheInMemory(true).cacheOnDisk(true).considerExifParams(false)
				.imageScaleType(ImageScaleType.IN_SAMPLE_INT).bitmapConfig(Bitmap.Config.RGB_565)
				// .displayer(new FadeInBitmapDisplayer(50))
				// .displayer(new SimpleBitmapDisplayer()).handler(new
				// Handler())
				.build();
		File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext());
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
				// .memoryCacheExtraOptions(, 800) // default = device screen
				// dimensions
				// .diskCacheExtraOptions(480, 800, Bitmap.CompressFormat.JPEG,
				// 75, null)
				.threadPoolSize(2).threadPriority(Thread.NORM_PRIORITY - 1)
				.tasksProcessingOrder(QueueProcessingType.FIFO).denyCacheImageMultipleSizesInMemory()
				.memoryCache(new LruMemoryCache(4 * 1024 * 1024)).memoryCacheSize(4 * 1024 * 1024)
				.memoryCacheSizePercentage(13) // default
				.diskCache(new UnlimitedDiscCache(cacheDir)).diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100)
				.diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
				.imageDownloader(new BaseImageDownloader(getApplicationContext())) // default
				.imageDecoder(new BaseImageDecoder(true)) // default
				.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
				.defaultDisplayImageOptions(defaultoptions).build();
		DisplayImageOptions defaultLogoOptions = new DisplayImageOptions.Builder().resetViewBeforeLoading(true)
				.cacheInMemory(true).cacheOnDisc(true).bitmapConfig(Bitmap.Config.ARGB_8888).build();
		ImageLoaderConfiguration LogoConfig = new ImageLoaderConfiguration.Builder(getApplicationContext())
				.threadPoolSize(1).threadPriority(Thread.NORM_PRIORITY - 1)
				.tasksProcessingOrder(QueueProcessingType.FIFO).denyCacheImageMultipleSizesInMemory()
				.memoryCache(new LruMemoryCache(1 * 1024 * 1024)).diskCache(new UnlimitedDiscCache(cacheDir))
				.defaultDisplayImageOptions(defaultLogoOptions).build();
		ImageLoader.getInstance().init(config);
	}
}
